/**
 * 静态模拟数据服务
 * 提供固定的模拟数据，不包含随机数生成
 * 用于在数据库连接失败时提供稳定的回退数据
 */

import { timeUtils } from './realData'

// 静态告警数据
const staticAlerts = [
  {
    id: 'ALT-001',
    type: 'crowding',
    severity: 'high',
    title: '急诊科患者聚集告警',
    location: '急诊科等候区',
    description: '等候区患者数量超出设计容量，当前密度3.2人/㎡',
    timestamp: new Date(Date.now() - 15 * 60 * 1000).toISOString(),
    status: 'active',
    assignee: '张医生',
    priority: 'high'
  },
  {
    id: 'ALT-002',
    type: 'equipment',
    severity: 'medium',
    title: 'MRI-01 设备维护提醒',
    location: '影像科B区',
    description: '设备运行时间达到维护周期，建议安排维护',
    timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(),
    status: 'pending',
    assignee: '技术部',
    priority: 'medium'
  },
  {
    id: 'ALT-003',
    type: 'environment',
    severity: 'low',
    title: '手术室03温度正常',
    location: '手术室03',
    description: '温度传感器检测正常，环境参数稳定',
    timestamp: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(),
    status: 'resolved',
    assignee: '后勤部',
    priority: 'low'
  }
]

// 静态患者流量数据
const staticPatientFlow = Array.from({ length: 24 }, (_, h) => {
  let baseFlow = 0

  // 模拟真实医院患者流量模式（固定值）
  if (h >= 7 && h <= 9) baseFlow = 180  // 早高峰
  else if (h >= 10 && h <= 11) baseFlow = 150
  else if (h >= 14 && h <= 16) baseFlow = 160  // 下午高峰
  else if (h >= 19 && h <= 21) baseFlow = 120   // 晚间
  else if (h >= 22 || h <= 6) baseFlow = 30     // 夜间
  else baseFlow = 100  // 其他时间

  return {
    hour: h,
    patients: baseFlow,
    timestamp: new Date().toISOString()
  }
})

// 静态科室数据
const staticDepartments = [
  { id: 'emergency', name: '急诊科', floor: 'L1', currentPatients: 45, capacity: 200, utilization: 22.5, status: 'normal' },
  { id: 'internal', name: '内科', floor: 'L2', currentPatients: 120, capacity: 150, utilization: 80.0, status: 'busy' },
  { id: 'surgery', name: '外科', floor: 'L3', currentPatients: 95, capacity: 120, utilization: 79.2, status: 'busy' },
  { id: 'pediatrics', name: '儿科', floor: 'L2', currentPatients: 75, capacity: 100, utilization: 75.0, status: 'normal' },
  { id: 'obstetrics', name: '妇产科', floor: 'L4', currentPatients: 60, capacity: 80, utilization: 75.0, status: 'normal' },
  { id: 'ophthalmology', name: '眼科', floor: 'L3', currentPatients: 35, capacity: 60, utilization: 58.3, status: 'normal' },
  { id: 'ent', name: '耳鼻喉科', floor: 'L3', currentPatients: 25, capacity: 50, utilization: 50.0, status: 'normal' },
  { id: 'dermatology', name: '皮肤科', floor: 'L2', currentPatients: 20, capacity: 40, utilization: 50.0, status: 'normal' },
  { id: 'cardiology', name: '心血管科', floor: 'L5', currentPatients: 70, capacity: 90, utilization: 77.8, status: 'busy' },
  { id: 'neurology', name: '神经科', floor: 'L5', currentPatients: 50, capacity: 70, utilization: 71.4, status: 'normal' },
  { id: 'icu', name: 'ICU', floor: 'L6', currentPatients: 30, capacity: 40, utilization: 75.0, status: 'normal' },
  { id: 'or', name: '手术室', floor: 'L4', currentPatients: 8, capacity: 12, utilization: 66.7, status: 'normal' }
]

// 静态设备数据
const staticEquipment = [
  {
    id: 'MRI-01',
    name: '核磁共振仪',
    type: 'imaging',
    location: '影像科B区',
    status: 'idle',
    uptime: 95.5,
    currentUtilization: 45,
    maintenanceDate: new Date(Date.now() + 15 * 24 * 60 * 60 * 1000),
    manufacturer: '西门子',
    model: 'Model-7500',
    year: 2020
  },
  {
    id: 'CT-01',
    name: 'CT扫描仪',
    type: 'imaging',
    location: '影像科A区',
    status: 'busy',
    uptime: 98.2,
    currentUtilization: 85,
    maintenanceDate: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000),
    manufacturer: '飞利浦',
    model: 'Model-6800',
    year: 2021
  },
  {
    id: 'XRAY-01',
    name: 'X光机',
    type: 'imaging',
    location: '影像科A区',
    status: 'idle',
    uptime: 92.8,
    currentUtilization: 30,
    maintenanceDate: new Date(Date.now() + 20 * 24 * 60 * 60 * 1000),
    manufacturer: 'GE',
    model: 'Model-4200',
    year: 2019
  }
]

// 静态KPI数据
const staticKPIs = {
  bedUtilization: {
    value: 89.5,
    target: 85,
    trend: 2.1,
    status: 'good',
    lastUpdate: new Date()
  },
  patientFlow: {
    value: 1250,
    target: 1200,
    trend: 4.2,
    status: 'good',
    lastUpdate: new Date()
  },
  equipmentEfficiency: {
    value: 92.3,
    target: 90,
    trend: 1.8,
    status: 'excellent',
    lastUpdate: new Date()
  },
  patientSatisfaction: {
    value: 4.6,
    target: 4.5,
    trend: 0.1,
    status: 'excellent',
    lastUpdate: new Date()
  },
  emergencyResponse: {
    value: 8.5,
    target: 10,
    trend: -0.5,
    status: 'good',
    lastUpdate: new Date()
  },
  averageWaitTime: {
    value: 25,
    target: 30,
    trend: -2.1,
    status: 'excellent',
    lastUpdate: new Date()
  }
}

// 静态数据服务
export const staticDataService = {
  getAllRealTimeData: () => ({
    timestamp: timeUtils.now(),
    hospital: {
      name: '杭州市第一人民医院',
      level: '三级甲等',
      address: '浙江省杭州市西湖区古翠路300号',
      phone: '0571-87065701',
      totalBeds: 1200,
      dailyCapacity: 3000,
      founded: '1958年',
      staff: 2800
    },
    alerts: staticAlerts,
    patientFlow: staticPatientFlow,
    departments: staticDepartments,
    equipment: staticEquipment,
    kpis: staticKPIs
  })
}
